<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<!-- localStorage和sessionSorage的区别 -->
<body>

    <button onclick="saveData()">点我保存一个数据</button>
    <button onclick="resaveData()">点我覆盖之前的数据</button>
    <button onclick="readData()">点我读取一个数据</button>
    <button onclick="removeData()">点我读删除一个数据</button>
    <button onclick="clearData()">点我清空数据</button>
    
    <script>
        let a={"name":"ltk","age":"19"}
       function saveData(){
            localStorage.setItem('msg',"李彤康"),
            localStorage.setItem('p',JSON.stringify(a));
        }
        function resaveData(){
            localStorage.setItem('msg',"ltkzs")
        }
        function readData(){
           console.log(JSON.parse(localStorage.getItem('p'))) ;
        }
       function removeData(){
            localStorage.removeItem("msg");
        }
        function clearData(){
            localStorage.clear();
        }
    </script>
</body>
</html>